package cn.hrlly.tao2shou.presenter;

import android.content.Context;

import cn.hrlly.tao2shou.biz.ShowSearchCommoditiesBiz;
import cn.hrlly.tao2shou.biz.ShowSearchCommoditiesBizImpl;
import cn.hrlly.tao2shou.domain.CommodityList;
import cn.hrlly.tao2shou.domain.HistorySearch;
import cn.hrlly.tao2shou.listener.OnShowSearchCommoditiesListener;
import cn.hrlly.tao2shou.view.view_interface.ShowSearchCommoditiesView;

/**
 * User: gengliang
 * Date: 2016-01-29
 * Time: 14:46
 */

public class ShowSearchCommoditiesPresenterImpl implements OnShowSearchCommoditiesListener,ShowSearchCommoditiesPresenter {

    private ShowSearchCommoditiesBiz showSearchCommoditiesBiz;
    private ShowSearchCommoditiesView showSearchCommoditiesView;

    public ShowSearchCommoditiesPresenterImpl(ShowSearchCommoditiesView showSearchCommoditiesView,Context context){
        this.showSearchCommoditiesBiz=new ShowSearchCommoditiesBizImpl(this,context);
        this.showSearchCommoditiesView=showSearchCommoditiesView;
    }

    //以下是showSearchCommoditiesPresenter
    @Override
    public void showSearchCommodities() {
        CommodityList commodityList=new CommodityList();
        commodityList.setAntistop(showSearchCommoditiesView.getAntistop());
        commodityList.setPage(showSearchCommoditiesView.getPage());
        commodityList.setPageCount(showSearchCommoditiesView.getPageCount());
        commodityList.setSortAccording(showSearchCommoditiesView.getSortAccording());
        commodityList.setLongitude(showSearchCommoditiesView.getLongitude());
        commodityList.setLantitude(showSearchCommoditiesView.getLantitude());
        showSearchCommoditiesBiz.showSearchCommodities(commodityList);
    }

    @Override
    public void closeDataBase() {
        showSearchCommoditiesBiz.closeDataBase();
    }

    //以下是onShowSearchCommoditiesListener
    @Override
    public void showSearchCommoditiesListenerSucc(CommodityList commodityList) {
        showSearchCommoditiesView.showListView(commodityList);

        //保存搜索记录
        HistorySearch historySearch=new HistorySearch();
        historySearch.setSearchName(showSearchCommoditiesView.getAntistop());
        showSearchCommoditiesBiz.saveHistorySearch(historySearch);
    }

    @Override
    public void showSearchCommoditiesListenerFail(String errorMessage) {
        showSearchCommoditiesListenerFail(errorMessage);
    }

    @Override
    public void showSearchCommoditiesListenerFail(int errorMessage) {
        showSearchCommoditiesListenerFail(errorMessage);
    }

}
